package samples.strategy_mode.context;

import lombok.SneakyThrows;
import samples.strategy_mode.enums.StrategyEnum;
import samples.strategy_mode.strategy.IStrategy;

public class SearchStrategyContext {
    private final IStrategy strategy;

    public SearchStrategyContext(IStrategy strategy) {
        this.strategy = strategy;
    }
      @SneakyThrows
      public SearchStrategyContext(StrategyEnum strategyEnum) {
          Class<?> clazz = Class.forName(strategyEnum.getStrategy());
          this.strategy = (IStrategy) clazz.getDeclaredConstructor().newInstance();
    }  @SneakyThrows
      public SearchStrategyContext(Integer strategyType) {
          Class<?> clazz = Class.forName(StrategyEnum.getStrategyByType(strategyType));
          this.strategy = (IStrategy) clazz.getDeclaredConstructor().newInstance();
    }

    public void doSearch(){
        strategy.doSelect();
    }
}
